package com.rainsoft.center.isec.common.utils;

import com.alibaba.fastjson.JSONObject;

import java.util.Map;


/**
 * @name GenerateClass
 * @description
 * @Author Star
 * @Version 2011-5-31上午11:15:06
 **/

public class GenerateClass {



	private static int parseInt(Object obj) {
		if (obj == null) {
			return 0;
		}
		try {
			return Integer.parseInt(obj.toString());
		} catch (NumberFormatException e) {
			return 0;
		}
	}

	public static String generateByJson(String json, String tableName, String family, String topicName) {
		Map map = JSONObject.parseObject(json, Map.class);
		StringBuilder str = new StringBuilder();

		str.append("\n@HTable(tableName =\"").append(tableName).append("\", family = \"").append(family).append("\"").append(", topicName = {\"").append
				(topicName).append("\"})");
		str.append("\npublic class ");
		String className = CamelCaseUtils.toCapitalizeCamelCase(tableName);
		str.append(className);
		str.append(" implements Serializable {");


		for (Object o : map.keySet()) {
			String s = String.valueOf(o);
			String s1 = CamelCaseUtils.toCamelCase(s);
			str.append("\n\t@JSONField(name = \"").append(o).append("\")");
			str.append("\n\t").append("private String ").append(s1).append(";").append("\n");
		}
		str.append("\n").append("}");
		return str.toString();
	}


	public static void main(String[] args) {
		System.out.println(generateByJson("{\"REMOTEPORT\":\"8080\",\"BCPNAME\":\"1510192800/11011221000021_1510193276_47049_0000110019.vu\"," +
				"\"CHECKIN_ID\":\"11011221000021115xxx11313X1495890266\",\"ZIPNAME\":\"11011221000021_1510192097_97932_0000110019.rsz\"," +
				"\"SESSIONID\":\"C0A800690810782707D25A01B380\",\"CAPTIME\":\"2017-11-09 10:08:16\",\"COMPUTERMAC\":\"08-10-78-27-07-D2\"," +
				"\"SERVICE_CODE\":\"11011221000021\",\"EXTENT_ACCOUNT1\":\"\",\"DATA_SOURCE\":\"1\",\"EXTENT_ACCOUNT2\":\"\",\"TERMINAL_LATITUDE\":\"\"," +
				"\"ROWNUMBER\":\"1\",\"COMPUTERIP\":\"192.168.0.105\",\"MACHINE_CODE\":\"NI945A1201403QF020\",\"USERNAME\":\"车艳明(手)\",\"COMPUTERPORT\":\"5817\"," +
				"\"IMSI_CODE\":\"\",\"TERMINAL_LONGITUDE\":\"\",\"IDTYPE\":\"111\",\"IDCODE\":\"22018219940111313X\",\"SERVICE_CODE_OUT\":\"11011221000021\"," +
				"\"ACTIONTYPE\":\"1\",\"MANUFACTURER_CODE\":\"596463021\",\"UNAME\":\"874963118\",\"PASSWORD\":\"\",\"ROOM_ID\":\"115\",\"UALIAS\":\"\"," +
				"\"IMEI_CODE\":\"\",\"SERVICETYPE\":\"1031002\",\"REMOTEIP\":\"106.52.39.125\"}","vid_loginout","info","vid_loginout"));
	}
}
